/*
 * @Description:
 * @Version: 2.0
 * @Date: 2024-04-09 15:07:30
 * @LastEditTime: 2024-06-06 17:16:13
 */
import MyReq from "@/config/request";
import {
  AccountEditPasswordReq,
  AccountEditReq,
  AccountLoginReq,
  AccountRegisterReq,
  AccountVerifyTokenReq,
  QueryReq,
} from "./req";
import { AccountLoginRes, AccountResInfo, GptResInfo } from "./res";
import { AxiosRequestConfig } from "axios";
import { CreateKbRequest, CreateKbResponse, BlockDataRes,KbSearchReq,KbSearchRes } from "./knowledge";

// 账户信息
export const AccountApi = {
  // 注册
  register: (req: AccountRegisterReq): Promise<undefined> => {
    return MyReq.post(`/api/user/register`, req);
  },
  // 登录
  login: (req: AccountLoginReq): Promise<AccountLoginRes> => {
    return MyReq.post(`/api/user/login`, req);
  },
  // 检测token是否有效/verify-token
  verifyToken: (req: AccountVerifyTokenReq): Promise<undefined> => {
    return MyReq.post(`/api/user/verify-token`, req);
  },
  //   修改个人信息
  edit: (req: AccountLoginReq): Promise<undefined> => {
    return MyReq.post(`/api/user/edit-userinfo`, req);
  },
  // 修改密码
  editPwd: (req: AccountEditPasswordReq): Promise<undefined> => {
    return MyReq.post(`/api/user/edit-password`, req);
  },
  //获取当前用户信息
  getCurAccountInfo: (): Promise<AccountResInfo> => {
    return MyReq.get(`/api/user/userinfo`);
  },
  // 退出登录
  logout: (): Promise<undefined> => {
    return MyReq.get(`/api/user/logout`);
  },
};

// 提问信息
export const QueryApi = {
  // 提问
  query: (req: QueryReq, signal: AbortSignal): Promise<string> => {
    // 传递信号，终止请求
    const config: AxiosRequestConfig = {
      signal,
    };
    return MyReq.post(`/api/ask`, req, config);
  },
};
// 知识库
export const KnowledgeApi = {
  // 查询所有知识库
  getAllKnowledgeData: (): Promise<undefined> => {
    return MyReq.get(`/api/list_kbs`);
  },
  // 新建知识库
  createKnowledgeBase: (req: CreateKbRequest): Promise<CreateKbResponse> => {
    return MyReq.post("/api/create_kb", req);
  },
  // 获取文件块列表
  getFileBlocks: (kb_id: number): Promise<BlockDataRes> => {
    return MyReq.get("/api/list", {
      params: { kb_id },
    });
  },
  SearchKbBlocks:(req:KbSearchReq):Promise<KbSearchRes>=>{
    return MyReq.post('/api/search',req)
  }
};
